//
//  BQSubmitOrderController.m
//  BeeQuick
//
//  Created by mac on 16/11/22.
//  Copyright © 2016年 six_group. All rights reserved.
//

#import "BQSubmitOrderController.h"
#import "BQPayMentCell.h"
#import "BQMyCarTool.h"
#import "BQPayTotalCell.h"
static NSString * paymentID = @"paymentID";
static NSString * quanID = @"quanID";
static NSString * payListID = @"payListID";
static NSString * jingXuanID = @"jingXuanID";
static NSString * heJiID = @"heJiID";
static NSString * mingxiID = @"mingxiID";
static NSString * mxID = @"mxID";
@interface BQSubmitOrderController ()<UITableViewDataSource,UITableViewDelegate>

@property(weak,nonatomic)UILabel *payLabel;

@end

@implementation BQSubmitOrderController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(UpdatemainUI:) name:@"updateUI" object:nil];
}
/**
 *  存放用户添加到购物车的商品数组
 *
 *  @return command
 */


#pragma mark - 通知更新
-(void)UpdatemainUI:(NSNotification *)Notification{
    
    
}

#pragma mark - 数据源
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 7;
    
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (section == 3) {
        
        return  myCar.CurrentGoodArrM.count;
    }
    return 1;
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
 
    self.payLabel.text = [NSString stringWithFormat:@"¥%.2f",myCar.showTotalPrice + 5];
    
    if (indexPath.section == 0 && indexPath.row == 0) {
        BQPayMentCell * cell = [tableView dequeueReusableCellWithIdentifier:paymentID forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else if (indexPath.section == 1 && indexPath.row == 0) {
        BQPayMentCell * cell = [tableView dequeueReusableCellWithIdentifier:quanID forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else if (indexPath.section == 2 && indexPath.row == 0) {
        BQPayMentCell * cell = [tableView dequeueReusableCellWithIdentifier:jingXuanID forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else if (indexPath.section == 4 && indexPath.row == 0) {
        BQPayTotalCell * cell = [tableView dequeueReusableCellWithIdentifier:heJiID forIndexPath:indexPath];
        //MARK: - 给实付款金额赋值.
        cell.totalPrice.text = [NSString stringWithFormat:@"%.2f",[myCar showTotalPrice]];
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else if (indexPath.section == 5 && indexPath.row == 0) {
        BQPayMentCell * cell = [tableView dequeueReusableCellWithIdentifier:mxID forIndexPath:indexPath];
        cell.zonge.text = [NSString stringWithFormat:@"%.2f",[myCar showTotalPrice]];
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else if (indexPath.section == 3){
        BQPayMentCell * cell = [tableView dequeueReusableCellWithIdentifier:payListID forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        cell.model = myCar.CurrentGoodArrM[indexPath.row]; 
        
        return cell;
    }
    UITableViewCell * cell = [[UITableViewCell alloc]init];
    
    
    return cell;
    
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0 && indexPath.section == 0) {
        return 300;
    }else if (indexPath.row == 0&& indexPath.section == 1){
        return 120;
    }else if (indexPath.section == 2){
        return 25;
    }else if (indexPath.section == 5){
         tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        return 193;
    }
    return 44;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    if (section == 3 ) {
        return 0;
    }else if (section ==4){
        return 0;
    }
    return 10;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}

#pragma mark - pop到上一个界面
-(void)buttonOF:(id)sender{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - 界面设置
-(void)setupUI{
    //MARK:界面设置
    self.view.backgroundColor = [UIColor cz_colorWithHex:0xf7f7f7];
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"v2_goback"] style:UIBarButtonItemStylePlain target:self action:@selector(buttonOF:)];
    self.navigationController.navigationBar.tintColor = [UIColor cz_colorWithHex:0x473c31];
    self.navigationItem.leftBarButtonItem = barButtonItem;
    self.navigationItem.rightBarButtonItem = nil;
    self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
    self.navigationItem.title = @"提交订单";
    self.tabBarController.tabBar.hidden = YES;
    //MARK:tableview搭建与设置
    
    UITableView * tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain ];
    [self.view addSubview:tableView];
    tableView.delegate = self;
    tableView.dataSource = self;
    
    UIView * footerview = [[UIView alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height-49, self.view.frame.size.width, self.view.frame.size.height)];
    footerview.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:footerview];
    
    UIButton * submit = [[UIButton alloc]init];
    submit.backgroundColor = [UIColor yellowColor];
    submit.titleLabel.font = [UIFont systemFontOfSize:13];
    [submit setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
    [submit setTitle:@"确认付款" forState:UIControlStateNormal];
    submit.frame = CGRectMake(self.view.frame.size.width-120, self.view.frame.size.height-49, 120 , 49);
    [self.view addSubview:submit];
    
    UILabel * payLabel = [[UILabel alloc]initWithFrame:CGRectMake(10,self.view.frame.size.height-34,80, 20)];
    payLabel.text = @"应付金额:";
    [payLabel setFont:[UIFont systemFontOfSize:13]];
    [payLabel setTextColor:[UIColor blackColor]];
    [self.view addSubview:payLabel];
    
    UILabel * moneyLabel = [[UILabel alloc]initWithFrame:CGRectMake(75, self.view.frame.size.height-34, 40, 20)];
    moneyLabel.text = [NSString stringWithFormat:@"¥%zd",12.1111];
    [moneyLabel setFont:[UIFont systemFontOfSize:13]];
    [moneyLabel setTextColor:[UIColor redColor]];
    [self.view addSubview:moneyLabel];
    self.payLabel = moneyLabel;
    //MARK: 注册
    [tableView registerNib:[UINib nibWithNibName:@"BQPayMentCell" bundle:nil] forCellReuseIdentifier:paymentID];
    [tableView registerNib:[UINib nibWithNibName:@"BQquanCell" bundle:nil] forCellReuseIdentifier:quanID];
    [tableView registerNib:[UINib nibWithNibName:@"BQPayListCell" bundle:nil] forCellReuseIdentifier:payListID];
    [tableView registerNib:[UINib nibWithNibName:@"BQjingXuan" bundle:nil] forCellReuseIdentifier:jingXuanID];
    [tableView registerNib:[UINib nibWithNibName:@"BQheJiCell" bundle:nil] forCellReuseIdentifier:heJiID];
    [tableView registerNib:[UINib nibWithNibName:@"BQMingXi" bundle:nil] forCellReuseIdentifier:mxID];
}
@end
